﻿
<!-- /SAMPLE BOX CONFIGURATION MODAL FORM-->
<div class="container">
<div class="row">
	<div id="content" class="col-lg-12">
		<!-- PAGE HEADER-->
		<div class="row">
			<div class="col-sm-12">
				<div class="page-header">
					<!-- STYLER -->

					<!-- /STYLER -->
					<!-- BREADCRUMBS -->
					<ul class="breadcrumb">
						<li>
							<i class="fa fa-home"></i>
							<a href="index.html">首页</a>
						</li>
						<li>
							<a href="#">分类模块</a>
						</li>
						<li>分类列表</li>
					</ul>
					<!-- /BREADCRUMBS -->
					<div class="clearfix">
						<h3 class="content-title pull-left">分类列表</h3>
					</div>
				</div>
			</div>
		</div>
		<!-- /PAGE HEADER -->
		<!-- DATA TABLES -->
		<div class="row">
			<div class="col-md-12">
				<!-- BOX -->
				<div class="box border green">
					<div class="box-title">
						<h4><i class="fa fa-table"></i>新闻列表</h4>
						<div class="tools hidden-xs">
							<a href="#box-config" data-toggle="modal" class="config">
								<i class="fa fa-cog"></i>
							</a>
							<a href="javascript:;" class="reload">
								<i class="fa fa-refresh"></i>
							</a>
							<a href="javascript:;" class="collapse">
								<i class="fa fa-chevron-up"></i>
							</a>
							<a href="javascript:;" class="remove">
								<i class="fa fa-times"></i>
							</a>
						</div>
					</div>
					<div class="box-body">
						<form action="" method="get" accept-charset="utf-8">
						<table id="datatable1" cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered table-hover">
							<thead>
								<tr  >
									<th width="100" >ID</th>
									<th>name</th>
									<th  class="hidden-xs col-lg-1">pid(父级)</th>
									<th class="hidden-xs col-lg-2" >编辑</th>
								</tr>
							</thead>
							<tbody>
								<?php foreach($cate as $value){ ?>
								<tr class="gradeX" pid="0" level="1">
									<td><?php echo $value['id']?></td>
									<td class="dbl" title='title'><button id="<?php echo $value['id'];?>" type="button"  class="btn btn-info but">+</button><?php echo $value['name']?></td>
									<td class="dbl" title='type' ><?php echo $value['pid']?></td>
									<td>
										<a href="index.php?c=cate&a=edit&admin=1&id=<?php echo $value['id']?>" class="btn btn-info"><i class="fa fa-pencil-square-o"></i> 编辑</a>
										<a h="index.php?c=cate&a=del&admin=1&id=<?php echo $value['id']?>" onclick="return confirm('真的要删除吗？')"  class="btn btn-2g btn-danger del">
										<i class="fa fa-trash-o "></i> 删除</a>
									</td>
								</tr>
								<?php } ?>
						</tbody>
				   </table>
				</form>
			</div>
		</div>
			<!-- /BOX -->
	</div>
</div>
						<!-- /DATA TABLES -->

<script src="resources/admin/js/jquery/jquery-2.0.3.min.js"></script>
	<script type="text/javascript">

	$(function(){
		$('.del').click(function(event) {
			var url = $(this).attr('h');
			$.ajax({
				url:url,
				type:'get',
				dataType:'json',
				success:function(json){
					if (json>0) {
					 if (confirm('您删除的数据下还有子级是否继续执行删除操作?')) {
						 location.href=url;
						};
					}else{
						location.href=url;
				 }
			   }
			})
			return false;
		});
	})

	$(function(){

		$('tbody').on('click','.but',function(){
				var id=$(this).attr('id');
				//console.log(id);
				var caa=$(this);
				var obj= $(this).parent().parent();

				if ('+'==$(this).text()){
				level = parseInt(obj.attr('level'));
				lefl = level*50;
				level++;
			 	$.ajax({
				url: 'index.php?c=cate&a=list&admin=1&id='+id,
				type: 'get',
				dataType: 'json',
				success:function(json){

				var html='';
				for (i in json) {
				html+='<tr class="gradeX" pid="'+id+'" level="'+level+'">';
				html+='<td>'+json[i].id+'</td>';
				html+='<td  class="dbl" style="padding-left:'+lefl+'px" title="title"><button id='+json[i].id+' type="button" class="btn btn-info but">+</button>'+json[i].name+'</td>';
				html+='<td class="dbl" title="type" >'+json[i].pid+'</td>';
				html+='<td><a class="btn btn-info" href="index.php?c=cate&a=edit&admin=1&id='+json[i].id+'"><i class="fa fa-pencil-square-o"></i> 编辑</a>';
				html+='<a class="btn btn-2g btn-danger del" href="index.php?c=cate&a=edit&admin=1&id='+json[i].id+'"><i class="fa fa-trash-o "></i> 删除</a>';
				html+='</td>';
				html+='</tr>';
				}
				html+='<tr style="display:none;" pid="'+json[i].pid+'" ></tr>';
				obj.after(html);
			}

                      })
			caa.text('-');
			}else{

				var pid=obj.attr('pid');
				obj.nextUntil('tr[pid='+pid+']').remove();caa.text('+');
			}

		})


	})



	</script>



